$(document).ready(function(){
	var classes = $("#classes");
	var professional = $("#professional");
	var systems_id = $("#systems_id");
	var professional_id = $("#professional_id");
	var classes_id = $("#classes_id");
	var url = '/schedule/querySystems';
	classes.hide();
	professional.hide();
	$.ajax({
		url:url,
		success:function(data){
			$(data.root).each(function(i,system){
				$("<option value='"+system.systems_id+"'>"+system.systems_name+"</option>").appendTo("#systems_id");
			});
		}
	});
	systems_id.change(function(){
		$("#professional_id option").remove();
		$("#classes_id option").remove();
		classes.hide();
		$("<option value=''>请选择</option>").appendTo("#professional_id");
		var str = $("#systems_id option:selected").val();
		if(str==""){
			$("#professional_id option").remove();
			$("#classes_id option").remove();
			classes.hide();
			professional.hide();
		}else{
			var url = '/schedule/queryProfessional?flag='+str;
			$.ajax({
				url: url,
				success:function(data){
					$(data.root).each(function(i,profession){
						$("<option value='"+profession.professional_id+"'>"+profession.professional_name+"</option>").appendTo("#professional_id");
						professional.show();
					});
				}
			});
		}
	});
	professional_id.change(function(){
		$("#classes_id option").remove();
		$("<option value=''>请选择</option>").appendTo("#classes_id");
		var str = $("#professional_id option:selected").val();
		if(str==""){
			$("#classes_id option").remove();
			classes.hide();
		}else{
			var url = '/schedule/queryClasses?flag='+str;
			$.ajax({
				url: url,
				success:function(data){
					$(data.root).each(function(i,classe){
						$("<option value='"+classe.classes_id+"'>"+classe.classes_name+"</option>").appendTo("#classes_id");
						classes.show();
					});
				}
			});
		}
	});
	$("#submit").click(function(){
		if($("#professional_id option:selected").val()==""||$("#systems_id option:selected").val()==""||$("#classes_id option:selected").val()==""){
			alert("学院或专业或班级不能为空");
			return false;
		}
		var scheduleName = "湖南文理学院"+$("#systems_id option:selected").text()+$("#season option:selected").val()+"学期分班课程表";
		window.returnValue = $("#systems_id option:selected").val()+","+$("#professional_id option:selected").val()+","+$("#classes_id option:selected").val()+","+$("#professional_id option:selected").text()+","+$("#classes_id option:selected").text()+","+scheduleName;
		//alert(window.returnValue);
		window.close();
		
	});
});